const { MongoClient } = require("mongodb");

// Replace the uri string with your MongoDB deployment's connection string.
const uri = ""


const client = new MongoClient(uri, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});

async function del() {
    try {
        await client.connect();

        const database = client.db("test");
        const movies = database.collection("movies");

        // create an array of documents to insert

        // this option prevents additional documents from being inserted if one fails
        // const options = { ordered: true };

        const result = await movies.deleteMany({ name: "Red", "bi": "1231" });
        console.log(`${result} documents were inserted`);
    } finally {
        await client.close();
    }
}

async function add() {
    try {
        await client.connect();

        const database = client.db("test");
        const movies = database.collection("movies");

        // create an array of documents to insert
        const docs = [
            { name: "Red", town: "Kanto", bi: "1231" },
            { name: "Blue", town: "Kanto", ehrhoqhuf: { dsjdskjfdsah: "fasdf" } }
        ];

        // this option prevents additional documents from being inserted if one fails
        // const options = { ordered: true };

        const result = await movies.insertMany(docs);
        console.log(`${result.insertedCount} documents were inserted`);
    } finally {
        await client.close();
    }
}

async function select() {
    await client.connect();

    const database = client.db("test");
    const movies = database.collection("movies");

    // this option prevents additional documents from being inserted if one fails
    // const options = { ordered: true };
    // await movies.insertMany([{ "quantity": 10, "price": 20 }, { "quantity": 21, "price": 10 }])
    const result = await movies.find({
        $or: [
            { quantity: { $lt: 20 } },
            { price: 10 }
        ]
    }).toArray();
    console.log(result);
    await client.close();


}

async function up() {
    await client.connect();

    const database = client.db("test");
    const movies = database.collection("movies");

    await movies.updateMany(
        {
            "test":"ghgfgygiyhfcgiyfhcy"
        },
        { $set: { price: 5 } },
        {
            upsert: true,
        }
    )
    const result = await movies.find({
        $or: [
            { quantity: { $lt: 20 } },
            { price: 10 }
        ]
    }).toArray();
    console.log(result);
    await client.close();

}

up();
